package me.zhengjie.modules.lock.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.modules.lock.service.LockDeviceService;
import me.zhengjie.modules.lock.service.dto.LockDeviceInfoDetailDTO;
import me.zhengjie.modules.lock.service.dto.LockDeviceInfoUnbindDTO;
import me.zhengjie.modules.lock.service.dto.LockLeaseBackCloseDTO;
import me.zhengjie.modules.lock.service.vo.LockDeviceInfoDetailReqVO;
import me.zhengjie.modules.lock.service.vo.LockDeviceInfoListReqVO;
import me.zhengjie.modules.lock.service.vo.LockDeviceInfoUnbindReqVO;
import me.zhengjie.modules.lock.service.vo.LockLeaseBackCloseReqVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"运营端门锁信息的接口"})
@RequestMapping("/api/v1/lock/device")
@RestController
public class LockDeviceController {

    @Autowired
    private LockDeviceService lockDeviceService;

    @AnonymousAccess
    //@PreAuthorize("@el.check('device:list')")
    @ApiOperation(value = "查询设备列表")
    @GetMapping("/list/page")
    public ResponseEntity<Object> selectLockList(LockDeviceInfoListReqVO reqVO, Pageable pageable) {
        return new ResponseEntity<>(lockDeviceService.selectLockInfoList(reqVO, pageable), HttpStatus.OK);
    }

    @AnonymousAccess
    //@PreAuthorize("@el.check('device:detail')")
    @ApiOperation(value = "查询设备列表")
    @GetMapping("/detail")
    public ResponseEntity<Object> detail(LockDeviceInfoDetailReqVO reqVO) {
        LockDeviceInfoDetailDTO detailDTO = lockDeviceService.detail(reqVO);
        return new ResponseEntity<>(detailDTO, HttpStatus.OK);
    }

    @AnonymousAccess
    @ApiOperation(value = "解绑设备")
    @PostMapping("/unbind")
    public ResponseEntity<Object> unbind(@RequestBody LockDeviceInfoUnbindReqVO reqVO) {
        LockDeviceInfoUnbindDTO unbindDTO = lockDeviceService.unbind(reqVO);
        return new ResponseEntity<>(unbindDTO, HttpStatus.OK);
    }

    @AnonymousAccess
    @ApiOperation(value = "关闭售后")
    @PostMapping("/closeLockLeaseBack")
    public ResponseEntity<Object> closeLockLeaseBack(@RequestBody LockLeaseBackCloseReqVO reqVO) {
        LockLeaseBackCloseDTO closeDTO = lockDeviceService.closeLockLeaseBack(reqVO);
        return new ResponseEntity<>(closeDTO, HttpStatus.OK);
    }

}
